home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / TABCNTRL.PAK / DEMO.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  208 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:    Demo.c
  9. //
  10. //  PURPOSE:   Displays 
  11. //
  12. //  FUNCTIONS:
  13. //    DemoInit         - Calls initialization routines
  14. //    CreateTabControl - Creates the tab control window. 
  15. //    InitTabControl   - Initializes the tab control with tabs
  16. //
  17. //  COMMENTS:
  18. //
  19. //
  20.  
  21. #include <windows.h>            // required for all Windows applications
  22. #include <windowsx.h>
  23. #include <commctrl.h>
  24. #include "globals.h"            // prototypes specific to this application
  25. #include "demo.h"
  26.  
  27.  
  28. HWND hwndTabControl;            // Global Window handle for tab control.
  29. HWND hwndDisplayChild;
  30. BOOL    CreateTabControl    (HWND hwndParent);
  31. void    InitializeTabControl(HWND hwndTabControl);
  32.  
  33.  
  34. //
  35. //  FUNCTION: DemoInit (HWND)
  36. //
  37. //  PURPOSE: Initializes the tab control
  38. //
  39. //  PARAMETERS:
  40. //    hwnd - The window handing the message.
  41. //
  42. //  RETURN VALUE:
  43. //    BOOL - to indicate success/failure
  44. //
  45. //  COMMENTS:
  46. //    
  47. //
  48.  
  49. BOOL DemoInit(HWND hwnd)
  50. {
  51.     
  52.     // initialize common controls..
  53.     InitCommonControls();
  54.  
  55.     // Call CreateTabControl() to create the tab control window. 
  56.     if(!CreateTabControl(hwnd))
  57.     {
  58.         MessageBox(hwnd, 
  59.                   (LPSTR)"ERROR: TAB CONTROL WAS NOT CREATED: CLOSING WINDOW)", 
  60.                   (LPSTR)"ERROR", 
  61.                   MB_OK);
  62.         return 0;
  63.  
  64.     }
  65.     // Call InitializeTabControl() to initialize the control and to create 
  66.     // the property page dialogs. 
  67.  
  68.     InitializeTabControl(hwndTabControl);
  69.     return TRUE;
  70. }
  71.  
  72.  
  73.   
  74.  
  75. //
  76. //  FUNCTION: CreateTabControl(HWND)
  77. //
  78. //  PURPOSE:  Create the Tab Control.
  79. //
  80. //  PARAMETERS:
  81. //    hwnd     - Parent Window Handle.
  82. //
  83. //  RETURN VALUE:
  84. //    returns TRUE if the tab control was created, else false.
  85. //
  86. //  COMMENTS:
  87. //    This function calls CreateWindow to create the tab control. The hwnd
  88. //    that is passed to this function is the parent window handle.
  89. //
  90.  
  91. BOOL CreateTabControl(HWND hwndParent)
  92. {
  93.     RECT dispRect;
  94.  
  95.     
  96.     GetClientRect(hwndParent, &dispRect);
  97.     hwndTabControl = CreateWindow(WC_TABCONTROL,
  98.                                   "",
  99.                                   WS_CHILD | WS_VISIBLE | WS_TABSTOP |
  100.                                   WS_CLIPSIBLINGS |
  101.                                   TCS_TOOLTIPS,  
  102.                                   dispRect.left  + 20,
  103.                                   dispRect.top   + 20,
  104.                                   dispRect.right - 50,
  105.                                   dispRect.bottom- 50,
  106.                                   hwndParent,
  107.                                   (HMENU)IDM_TABCONTROL,
  108.                                   hInst,
  109.                                   (LPVOID) NULL);
  110.  
  111.     if(hwndTabControl)
  112.         return TRUE;
  113.     else
  114.         return FALSE;
  115. }
  116.  
  117.  
  118. //
  119. //  FUNCTION: InitializeTabControl(HWND)
  120. //
  121. //  PURPOSE:  Initialize the Tab Control.
  122. //
  123. //  PARAMETERS:
  124. //    hwnd     - TabControl  Window Handle.
  125. //
  126. //  RETURN VALUE:
  127. //    None.
  128. //
  129. //  COMMENTS:
  130. //    This function calls TabCtrl_InsertItem to insert items into
  131. //    the tab control. The hwnd that is passed to this function is
  132. //    is the  window handle of the tab control created earlier.
  133. //    It also creates the child modeless dialogs that are displayed
  134. //    as property sheets.
  135. //
  136.  
  137. void InitializeTabControl(HWND hwndTabControl)
  138. {
  139.     int         i;                    // variable used in the FOR loop.
  140.     RECT        tabRect, tabItemRect; // Rectangles to position Page Dialogs.
  141.     char        szBuffer[64];
  142.     TC_ITEM     myTCItem;             // Array of TC_ITEM structures
  143.     HIMAGELIST  hWndImageList;        // Image list window handle.
  144.     HBITMAP     hBmp;
  145.  
  146.  
  147.     TabCtrl_GetItemRect (hwndTabControl, 0, &tabItemRect);
  148.     GetClientRect (hwndTabControl, &tabRect);
  149.  
  150.     // Initialize the image list by creating it first. 
  151.     // Our Tab Control uses IMAGELISTS. 
  152.     
  153.     hWndImageList = ImageList_Create (32, 32, FALSE, 4, 4);
  154.     if (!hWndImageList)
  155.         MessageBox(NULL, "Image List not initialized", "ERROR", MB_OK);
  156.  
  157.     hBmp = LoadBitmap (hInst, "IMAGES");
  158.     ImageList_Add (hWndImageList, hBmp, NULL);
  159.     DeleteObject (hBmp);
  160.  
  161.  
  162.     // Fail if not all images were added.
  163.     if (ImageList_GetImageCount (hWndImageList) < 4)
  164.         MessageBox(NULL, "Bitmaps not added to Image List", "ERROR", MB_OK);
  165.     
  166.     // Initialize the Tab control with text and images from the 
  167.     // resource and image
  168.     for(i = 0; i < 4; i++)
  169.     {
  170.  
  171.         // Load the string for the TABS from the RC file.
  172.         LoadString(hInst, IDS_START+i, szBuffer, sizeof(szBuffer));
  173.  
  174.         myTCItem.mask      = (UINT)TCIF_TEXT | TCIF_IMAGE;
  175.         myTCItem.pszText   = (LPSTR)szBuffer;
  176.         myTCItem.cchTextMax= sizeof(szBuffer);
  177.         myTCItem.iImage    = i;
  178.  
  179.         TabCtrl_InsertItem (hwndTabControl,
  180.                            (int) i,
  181.                            (TC_ITEM FAR*)&myTCItem);
  182.  
  183.     }
  184.  
  185.  
  186.     (void) TabCtrl_SetImageList(hwndTabControl, hWndImageList);
  187.     TabCtrl_SetCurSel (hwndTabControl, 0);
  188.     SetFocus (hwndTabControl);
  189.  
  190.     // Create child window inside tab control
  191.     // to display bitmap.
  192.     hwndDisplayChild = CreateWindowEx(WS_EX_CLIENTEDGE,
  193.                                     szChildName,
  194.                                     "",
  195.                                     WS_CHILD | WS_VISIBLE | WS_BORDER,  
  196.                                     tabRect.left + 10,
  197.                                     tabItemRect.bottom + 30,
  198.                                     tabRect.right - 20,
  199.                                     tabRect.bottom - tabItemRect.bottom
  200.                                     - 40,
  201.                                     hwndTabControl,
  202.                                     (HMENU)IDM_DISPLAYCHILD,
  203.                                     hInst,
  204.                                     (LPVOID) NULL);
  205.  
  206.         
  207. }
  208.